/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class PreguntaDAOImpl implements orm.dao.PreguntaDAO {
	public Pregunta loadPreguntaByORMID(int pre_id) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return loadPreguntaByORMID(session, pre_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta getPreguntaByORMID(int pre_id) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return getPreguntaByORMID(session, pre_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByORMID(int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return loadPreguntaByORMID(session, pre_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta getPreguntaByORMID(int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return getPreguntaByORMID(session, pre_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByORMID(PersistentSession session, int pre_id) throws PersistentException {
		try {
			return (Pregunta) session.load(orm.Pregunta.class, new Integer(pre_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta getPreguntaByORMID(PersistentSession session, int pre_id) throws PersistentException {
		try {
			return (Pregunta) session.get(orm.Pregunta.class, new Integer(pre_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByORMID(PersistentSession session, int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pregunta) session.load(orm.Pregunta.class, new Integer(pre_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta getPreguntaByORMID(PersistentSession session, int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pregunta) session.get(orm.Pregunta.class, new Integer(pre_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta[] listPreguntaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return listPreguntaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta[] listPreguntaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return listPreguntaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta[] listPreguntaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pregunta as Pregunta");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Pregunta[]) list.toArray(new Pregunta[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta[] listPreguntaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pregunta as Pregunta");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Pregunta[]) list.toArray(new Pregunta[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return loadPreguntaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return loadPreguntaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Pregunta[] preguntas = listPreguntaByQuery(session, condition, orderBy);
		if (preguntas != null && preguntas.length > 0)
			return preguntas[0];
		else
			return null;
	}
	
	public Pregunta loadPreguntaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Pregunta[] preguntas = listPreguntaByQuery(session, condition, orderBy, lockMode);
		if (preguntas != null && preguntas.length > 0)
			return preguntas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePreguntaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return iteratePreguntaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePreguntaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Libro2PersistentManager.instance().getSession();
			return iteratePreguntaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePreguntaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pregunta as Pregunta");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePreguntaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pregunta as Pregunta");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta createPregunta() {
		return new orm.Pregunta();
	}
	
	public boolean save(orm.Pregunta pregunta) throws PersistentException {
		try {
			orm.Libro2PersistentManager.instance().saveObject(pregunta);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Pregunta pregunta) throws PersistentException {
		try {
			orm.Libro2PersistentManager.instance().deleteObject(pregunta);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Pregunta pregunta)throws PersistentException {
		try {
			orm.Resultado[] lResultados = pregunta.resultado.toArray();
			for(int i = 0; i < lResultados.length; i++) {
				lResultados[i].setPreguntapre(null);
			}
			return delete(pregunta);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Pregunta pregunta, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Resultado[] lResultados = pregunta.resultado.toArray();
			for(int i = 0; i < lResultados.length; i++) {
				lResultados[i].setPreguntapre(null);
			}
			try {
				session.delete(pregunta);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Pregunta pregunta) throws PersistentException {
		try {
			orm.Libro2PersistentManager.instance().getSession().refresh(pregunta);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Pregunta pregunta) throws PersistentException {
		try {
			orm.Libro2PersistentManager.instance().getSession().evict(pregunta);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta loadPreguntaByCriteria(PreguntaCriteria preguntaCriteria) {
		Pregunta[] preguntas = listPreguntaByCriteria(preguntaCriteria);
		if(preguntas == null || preguntas.length == 0) {
			return null;
		}
		return preguntas[0];
	}
	
	public Pregunta[] listPreguntaByCriteria(PreguntaCriteria preguntaCriteria) {
		return preguntaCriteria.listPregunta();
	}
}
